understanding scope in javascript